package com.lmx.repoDomain.tmodel;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiLookupIncludeAutomatically;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.lmx.repoDomain.tmodel.business.User;

/**
 * 系评估问卷模版表
 */
@JsonApiResource(type = "evaluatemodel")
@Table(name = "tnb_evaluate_model")
@Entity
public class EvaluateModel extends BaseEntity {

	private Dicttype type;// 类型

	private String remark;// 备注

	private String title;// 名称

	private User lastUpdateUser;// 更新操作者userid

	private Integer createDateTime;// 创建时间

	private User createUser;

	private Integer lastUpdateDateTime;// 更新时间

	private List<EvaluateQuestion> questions;// 所包含问题

	private List<EvaluateScoreScope> scorescopes;// 分数范围

	private Short useFlag;// 是否可用 0 可用 1 不可用

	private RiskAssessModel riskAssessModel;

	private EvaluateModelSource modelSource; // 北京市统一评估模版 其他模版

	private EvaluateModelType modelType;

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "model_type_id", foreignKey = @ForeignKey(name = "null"))
	public EvaluateModelType getModelType() {
		return modelType;
	}

	public void setModelType(EvaluateModelType modelType) {
		this.modelType = modelType;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "model_source_id", foreignKey = @ForeignKey(name = "null"))
	public EvaluateModelSource getModelSource() {
		return modelSource;
	}

	public void setModelSource(EvaluateModelSource modelSource) {
		this.modelSource = modelSource;
	}

	@JsonApiToMany
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "model")
	public List<EvaluateScoreScope> getScorescopes() {
		return scorescopes;
	}

	public void setScorescopes(List<EvaluateScoreScope> scorescopes) {
		this.scorescopes = scorescopes;
	}

	@Column(name = "use_flag")
	public short getUseFlag() {
		if (this.useFlag == null) {
			this.useFlag = 0;
		}
		return this.useFlag;
	}

	public void setUseFlag(Short useFlag) {
		if (useFlag == null) {
			useFlag = 0;
		}
		this.useFlag = useFlag;
	}

	@JsonApiToMany
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "model")
	public List<EvaluateQuestion> getQuestions() {
		return questions;
	}

	public void setQuestions(List<EvaluateQuestion> questions) {
		this.questions = questions;
	}

	@Column(name = "createDateTime")
	public Integer getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(Integer createDateTime) {
		this.createDateTime = createDateTime;
	}

	@Column(name = "lastUpdateDateTime")
	public Integer getLastUpdateDateTime() {
		return lastUpdateDateTime;
	}

	public void setLastUpdateDateTime(Integer lastUpdateDateTime) {
		this.lastUpdateDateTime = lastUpdateDateTime;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "createuser_id", foreignKey = @ForeignKey(name = "null"))
	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "lastupdateuser_id", foreignKey = @ForeignKey(name = "null"))
	public User getLastUpdateUser() {
		return lastUpdateUser;
	}

	public void setLastUpdateUser(User lastUpdateUser) {
		this.lastUpdateUser = lastUpdateUser;
	}

	@Column(name = "title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public EvaluateModel() {
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "type_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getType() {
		return type;
	}

	public void setType(Dicttype type) {
		this.type = type;
	}

	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JsonApiToOne
	@JsonApiLookupIncludeAutomatically
	@JoinColumn(name = "risk_model_id")
	public RiskAssessModel getRiskAssessModel() {
		return riskAssessModel;
	}

	public void setRiskAssessModel(RiskAssessModel riskAssessModel) {
		this.riskAssessModel = riskAssessModel;
	}
}
